<?php

namespace App\Http\Models;


class FightApply extends BaseMessage
{

    protected $table = 'tfightapply';
    protected $fillable = ['FACustomerID', 'FAMessage', 'FAFID'];
    protected $guarded = ['id'];
    public static $rule = array(
        'FACustomerID' => 'required',
        'FAFID' => 'required',
    );


    public static function doCheck($id)
    {
        if (Fight::where('FCustomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->where('FID', $id)->first()) {
            return 1;
        }
        $data = self::where('FAFID', $id)->where('FACustomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->first();
        if ($data) {
            return 1;
        } else {
            return 0;
        }
    }

    public static function getAoolys($id)
    {
        return self::where('FAFID', $id)->leftJoin('tcustomer', 'tcustomer.CID', '=', 'tfightapply.FACustomerID')->select('tfightapply.FAID', 'tfightapply.FARes', 'tfightapply.FAMessage', 'tcustomer.CMobile', 'tcustomer.CName')->get();
    }

    public function doChange($FAID, $FARes)
    {
        return self::where('FAID', $FAID)->update(['FARes' => $FARes]);
    }
    public function myApply(){
        return self::where('FACustomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->leftJoin('tfight','tfight.FID','=','tfightapply.FAFID')->select('tfightapply.*','tfight.FTitle','tfight.FBeginAt')->paginate(5);
    }

}
